<template>
  <div class="login-container">
    <van-nav-bar title="登录" left-arrow @click-left="$router.back()" />

    <van-form @submit="onSubmit">
      <van-field
        v-model="user.mobile"
        name="mobile"
        label="手机号"
        placeholder="手机号"
        :rules="[{ required: true, message: '请填写手机号' }]"
      />
      <van-field
        v-model="user.code"
        name="code"
        center
        clearable
        label="短信验证码"
        placeholder="请输入短信验证码"
      >
        <template #button>
          <van-button
            size="small"
            type="primary"
            round
            @click.prevent="onSendSms"
            >发送验证码</van-button
          >
        </template>
      </van-field>
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>

    <!-- <span>
      账号： 13911111111 密码：246810<br />
      万能验证码： 246810
    </span> -->
  </div>
</template>

<script>
import { login, getValidateCode } from "@/api/user";

export default {
  name: "loginIndex",
  components: {},
  props: {},
  data() {
    return {
      user: {
        mobile: "",
        code: ""
      }
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    async onSendSms() {
      if (this.user.mobile.trim().length != 11) {
        return alert("手机号码格式不正确");
      }
      let { data } = await getValidateCode(this.user.mobile.trim());
      console.log(data);
    },
    async onSubmit() {
      let { data } = await login(this.user);
      console.log(data);
    }
  }
};
</script>

<style scoped lang="less">
</style>